package model

import (
	"github.com/gomodule/redigo/redis"
	"tizhi_front/nspel"
)

type ConsultType struct {
	Id           int64  `gorm:"primary_key;column:id"`
	Name         string `gorm:"column:name"`
	Introduction string `gorm:"column:introduction"`
	Label        string `gorm:"column:label"`
	PicUrl       string `gorm:"column:pic_url"`
}

func (*ConsultType) TableName() string {
	return "consult_type"
}

type ConsultTypeE struct{}

func (c *ConsultTypeE) SelectAll() (consultTypes []ConsultType, err error) {
	key := "consult_type.all"
	err = nspel.RedisGetGob(key, &consultTypes)
	if err == nil {
		return
	}
	if err != redis.ErrNil {
		nspel.Error(err)
	} else {
		err = nil
	}
	if err = nspel.GetOrm().Select([]string{"id", "name", "introduction", "label", "pic_url"}).Find(&consultTypes).Error; err != nil {
		return
	}
	nspel.RedisSetGob(key, consultTypes)
	return
}
